package com.tony.thread;

public class AddReduceThread{
    private int j =0;
    public void add(){
        j++;
        System.out.println(Thread.currentThread().getName()+"结果："+j);
    }
    public void reduce(){
        j--;
        System.out.println(Thread.currentThread().getName()+"结果："+j);
    }

    public static void main(String[] args) {
        final AddReduceThread addReduceThread = new AddReduceThread();
        for(int i=0;i<2;i++){
            new Thread(new Runnable() {
                @Override
                public void run() {
                    while(true){
                        addReduceThread.add();
                    }
                }
            }).start();
            new Thread(new Runnable() {
                @Override
                public void run() {
                    while(true){
                        addReduceThread.reduce();
                    }
                }
            }).start();
        }
    }

}
